//
//  receiveFirCirOneNew.m
//  tcpoctest
//
//  Created by gump on 5/9/13.
//  Copyright (c) 2013 gump. All rights reserved.
//

#import "receiveFirCirOneNew.h"

#import "FirCirLocalInfo.h"

#import "FirCirLocalResourceDataSource.h"
#import "FirendCircleDataSource.h"
#import "FirCirNewsDataSource.h"
#import "FirCirPictureIDdb.h"

#import "FirendCirLocalPathdb.h"
#import "fircirnewsdb.h"
#import "firendCircledb.h"

@implementation receiveFirCirOneNew

-(void)processreceive
{
    //返回 74char(1),9char(1),用户名长度char(1), 用户名char(x),
    //动态ID字串长度char(1),动态ID字串char(x),时间字串长度char(1),
    //时间字串char(x),区分值char(1)1文字\2语音,二进制数据长度int，
    //二进制数据char(x),评论数int,图片数char(1),[图片ID名称长度char(1),
    //图ID片名称char(x),图片url字串长度char(1), 图片url字串char(x)]*图片数
    //备注：如果区分值是语音 二进制数据是URL
    
    FriendStatus *fs = [[FriendStatus alloc] init];
    
    fs.mail = [logicsb ReadUnencodeString];
    fs.statusId = [logicsb ReadUnencodeString];
    fs.strtime = [logicsb ReadUnencodeString];
    fs.stIndex = [logicsb ReadChar];
    int strlength = [logicsb ReadIntWithTT:NTT_BIG2SMALL];
    fs.statusText = [logicsb ReadStringWithLength:strlength];
    if(fs.stIndex == FCG_ONE_SOUND)
    {
        FirCirLocalInfo *fclinfo = [[FirCirLocalInfo alloc] init];
        fclinfo.resourceID = fs.statusId;
        fclinfo.url = fs.statusText;
        fclinfo.localpath = @"";
        
        [[DataControl shareControl].fcLocalRecDS AddLocalRs:fclinfo];
        [[DataBaseCtrol shareControl].fircirlocaldatabase insertLocalPath:fclinfo];
    }
    
    fs.commentsCount = [logicsb ReadIntWithTT:NTT_BIG2SMALL];
    [logicsb ReadChar];
    
    while (logicsb.mrestLength > 0)
    {
        NSString *strpictureID = [logicsb ReadUnencodeString];
        NSString *strPictureUrl = [logicsb ReadUnencodeString];
        
        [fs.imageIDArray addObject:strpictureID];
        FirCirLocalInfo *fclinfo = [[FirCirLocalInfo alloc] init];
        fclinfo.resourceID = strpictureID;
        fclinfo.url = strPictureUrl;
        fclinfo.localpath = @"";
        [[DataControl shareControl].fcLocalRecDS AddLocalRs:fclinfo];
        [[DataBaseCtrol shareControl].fircirlocaldatabase insertLocalPath:fclinfo];
        
        [[DataBaseCtrol shareControl].fircirPIDdatabase
         insertPID:fs.statusId
         withPictureID:strpictureID];
    }
    
    [[DataControl shareControl].fcnewsDS AddNews:fs];
    [[DataBaseCtrol shareControl].fircirnewdatabase insertNews:fs];
    
    [[DataControl shareControl].fcnewsDS RemoveSearchObjectbyID:fs.statusId];
    //update firend circle ui
    
    [[DataControl shareControl].UICommendDS addUICommand:UC_REFRESHCURVIEW];
    
    [self ShowLog];
}

@end
